import Vue from 'vue'
import App from './App.vue'
// 引入路由
import router from '@/router/router.js'
// 引入框架模块
import ElementUI from 'element-ui'
import store from '@/store.js'
import 'element-ui/lib/theme-chalk/index.css'
import '@/styles/index.less'
Vue.use(ElementUI)
Vue.config.productionTip = false
// 添加路由导航
router.beforeEach((to, from, next) => {
  // 获取token
  var token = localStorage.getItem('heima_token')
  // 如果没有token值，除非你去登录，否则都应该跳转到登录页面
  if (token || to.path === '/login') {
    // 如果有token，那么就执行下一步
    next()
  } else if (!token && to.path !== '/login') {
    next({ name: 'login' })
  }
})

new Vue({
  // 注入路由
  router,
  store,
  render: h => h(App)
}).$mount('#app')
